package com.sy.controller.purchase;

import com.sy.bean.purchase.QueryReturnOrder;
import com.sy.bean.purchase.ReturnOrder;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.purchase.ReturnOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "purchase=退货单管理")
@RequestMapping("/api/returnOrder")
public class ReturnOrderController extends BaseController {


    @Autowired
    ReturnOrderService returnOrderService;

    @ApiOperation("添加退货单")
    @PostMapping("/add")
    public ResultBean add(@RequestBody ReturnOrder returnOrder) {
        int rs=returnOrderService.save(returnOrder);
        return rs>0?success("添加退货单成功"):fail("添加退货单失败");
    }

    @ApiOperation("批量删除退货单")
    @DeleteMapping("/delete")
    public ResultBean delete(@RequestParam("ids")List<Integer> ids) {
        int rs=returnOrderService.batchDelete(ids);
        return rs>0?success("删除退货单成功"):fail("删除退货单失败");
    }

    @ApiOperation("查询退货单列表详情")
    @GetMapping("/get")
    public ResultBean get(int id) {
        ReturnOrder returnOrder=returnOrderService.get(id);
        return success("查询退货单成功",returnOrder);
    }

    @ApiOperation("查询退货单列表")
    @PostMapping("/query")
    public ResultBean query(@RequestBody QueryReturnOrder queryReturnOrder){
        PageBean bean=returnOrderService.query(BeanOfMap.bom(queryReturnOrder));
        return success("查询退货单列表成功",bean);
    }
}
